;;; af
;;; Language: R5RS

; > (cube (my-cube-root 27))
; 27.000014608735402

(define (cube x) (* x x x))

(define (square x) (* x x))

(define (cube-root-iter guess x)
  (if (good-enough? guess x)
      guess
      (cube-root-iter (improve guess x)
                      x)))

(define (improve guess x)
  (/ (+ (/ x (square guess)) (* 2 guess)) 3))

(define (good-enough? guess x)
  (< (abs (/ (- (cube guess) x) x)) 0.001))

(define (my-cube-root x)
  (cube-root-iter 1.0 x))